#ifndef DJIRC_H
#define DJIRC_H

#include "usart_interface.h"

#define DJI_RC_RECEIVE_SIZE            ((uint8_t)18)

#define RC_CH_VALUE_MIN             ((uint16_t)364)
#define RC_CH_VALUE_OFFSET          ((uint16_t)1024)
#define RC_CH_VALUE_MAX             ((uint16_t)1684)
#define RC_CH_VALUE_DEAD            ((uint16_t)50)
#define RC_CH_VALUE_RANGE           ((uint16_t)660)

#define RC_SW_UP                    ((uint8_t)1)
#define RC_SW_MID                   ((uint8_t)3)
#define RC_SW_DOWN                  ((uint8_t)2)

class DJIRC {
private:
    #pragma pack(1)

    struct RCChannel {
        uint16_t Ch0 ;//右水平
        uint16_t Ch1 ;//右垂直
        uint16_t Ch2 ;//左水平
        uint16_t Ch3 ;//左垂直
        uint16_t Ch4 ;//左下方旋钮
        uint8_t SW_L ;//左拨码开关
        uint8_t SW_R ;//右拨码开关
    };
    
public:
    #pragma pack()

    //摇杆和旋钮经过处理后的值，乘以速度幅值可直接作为速度使用
    typedef struct
    {
        float left_upright;
        float left_level;
        float right_upright;
        float right_level;
        float knob;
    }RockerValue;

    /**摇杆值
     * @param 正方向 水平向左，垂直向上
     * @param Ch0 右水平
     * @param Ch1 右垂直
     * @param Ch2 左水平
     * @param Ch3 左垂直
     * @param Ch4 旋钮
    */
    RockerValue m_rocker_value;
    uint8_t m_data_receive_frame[DJI_RC_RECEIVE_SIZE];
    RCChannel channel;
    Usart* usart_djirc;

    uint16_t usKeyboard;//TODO:键盘按键值
    //TODO:[键鼠]键鼠模式
    bool PRESSED_W = false;       //控制前进
    bool PRESSED_S = false;       //控制后退
    bool PRESSED_A = false;       //控制左转
    bool PRESSED_D = false;       //控制右转
    bool PRESSED_SHIFT = false;   //
    bool PRESSED_CTRL = false;    //
    bool PRESSED_Q = false;       //
    bool PRESSED_E = false;       //
    bool PRESSED_R = false;       //
    bool PRESSED_F = false;       //
    bool PRESSED_G = false;       //
    bool PRESSED_Z = false;       //
    bool PRESSED_X = false;       //
    bool PRESSED_C = false;       //控制小陀螺
    bool PRESSED_V = false;       //操作手目视得到对方平步ID，按V发送，按一下ID3，按两下ID4，按三下ID5
    bool PRESSED_B = false;       //


    DJIRC(){
        usart_djirc = new Usart();
    }

    void SetUartHandle(USART_TypeDef* USARTx);
    void ChannelValueUpdate(void);
};

#endif